package com.trust.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trust.agri.response.ResponseResult;
import com.trust.agri.sign.validate.SaveValidate;
import com.trust.annotation.SYQLog;
import com.trust.entity.DTO.FarmPlantDTO;
import com.trust.entity.FarmPlant;
import com.trust.entity.Param.FarmPlantListParam;
import com.trust.entity.VO.FarmPlantVO;
import com.trust.service.FarmPlantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/api/farmP/plant")
@Api(value = "农事作业 - 种植任务 种植", tags = "农事作业 - 种植任务 种植")
public class FarmPlantController {


    @Resource
    private FarmPlantService service;

    /**
     * 种植列表
     * @param param
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("种植列表")
    public ResponseResult<Page<FarmPlantVO>> list(@RequestBody FarmPlantListParam param){
        Page<FarmPlantVO> page = service.list(param);
        return ResponseResult.ok(page);
    }

    /**
     * 新增种植
     * @param param
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增种植")
    @SYQLog(type = "新增种植", name = "种植任务 种植")
    public ResponseResult<FarmPlant> save(@Validated(SaveValidate.class) @RequestBody FarmPlantDTO param){
        FarmPlant farmPlant = service.saveAndUpdate(param);
        return ResponseResult.ok(farmPlant);
    }
}
